import React, { useState } from "react";
import Lanlogin from "../../components/Lanlogin";
import { Button, NavBar } from "antd-mobile";
import { useNavigate } from "react-router-dom";
import Swipers from "../../components/Swipers";
import "./index.scss";
import { useSelector } from "react-redux";

function Home() {
  const navigate = useNavigate();
  const { start, end, date } = useSelector((store) => store.city);

  const [citys, setCitys] = useState(localStorage.getItem("city") || "北京");
  const back = () => console.log("asd");
  // navigate("/city");

  const golist = () => {
    const token = localStorage.getItem('token')
    if(token){
      navigate("/list");
    }else{
      navigate('/login')
    }
    
  };


  // 左
  const goleft = ()=>{
    navigate('/city')
    localStorage.setItem('left','left')
  }
  // 右
const goright = ()=>{
    navigate('/city')
    localStorage.setItem('left','right')
  }
  return (
    <div>
      <NavBar back={citys} onBack={back} backIcon={false}>
        首页
      </NavBar>
      {/* 轮播 */}
      <Swipers></Swipers>
      <div className="cityp">
        <div>
          <p onClick={()=>goleft()}>{start}</p>
          <p>换</p>
          <p onClick={()=>goright()}>{end}</p>
        </div>
        <h2>{date}</h2>
        <Button
          block
          color="primary"
          onClick={() => {
            golist();
          }}
          size="large"
          style={{ width: "80%", left: "10%", top: "30px" }}
        >
          查询
        </Button>
      </div>
    </div>
  );
}

export default Lanlogin(Home);
